// JavaScript Document

function validarPresence(id)
{
	
	var username = new LiveValidation(id, {validMessage: ' ', wait: 500});
	username.add(Validate.Presence, {failureMessage: "No debe estar vacio!"});
	username.add(Validate.Format, {pattern: /([A-Za-z]+)*\d*_*/i, failureMessage: "No válido" } );
}

function validarPresencia(id)
{
    var password = new LiveValidation(id, {validMessage: ' ', wait: 500});
	password.add(Validate.Presence, {failureMessage: "No debe estar vacío"});
}

function validarNombre()
{
	var nombre = new LiveValidation('nombre', {validMessage: 'Ok', wait: 500});
	nombre.add(Validate.Presence, {failureMessage: "El nombre es requerido"});
	nombre.add(Validate.Length, {minimun: 2, tooShortMessage: "Nombre debe poseer al menos 2 caracteres."});
	nombre.add(Validate.Format, {pattern: /^[A-Za-z]+$/i, failureMessage: "Solo se admiten caracteres alfabeticos."});
}

function validarConsulta()
{
	var consulta = new LiveValidation('consulta', { validMessage: 'ok', wait: 500});
	consulta.add( Validate.Format, { pattern: /^([A-Za-z0-9])+$/i, failureMessage: "No se admiten caracteres especiales" } );
}

function validarApellido()
{
	var apellido = new LiveValidation('apellido', {validMessage: 'Ok', wait: 500});
	apellido.add(Validate.Presence, {failureMessage: "Escriba su Apellido."});
	apellido.add(Validate.Length, {minimun: 2, tooShortMessage: "Apellido debe poseer al menos 2 caracteres."});
	apellido.add(Validate.Format, {pattern: /^[A-Za-z]+$/i, failureMessage: "Solo se admiten caracteres alfabeticos."});
}

function validarCedula()
{
	var cedula = new LiveValidation('cedula', {validMessage: 'Ok', wait: 500});
	cedula.add(Validate.Presence, {failureMessage: "Campo Cedula es requerido."});
	cedula.add(Validate.Numericality, {onlyInteger: true, notANumberMessage: "Cedula solo puede contener numeros"});
	cedula.add(Validate.Length, {minimun: 6, tooShortMessage: "Cedula debe contener al menos 6 numeros.", maximun: 8, 
			   tooLongMessage: "Cedula debe tener maximo 8 numeros."});
}

function validarDireccion()
{
	var direccion = new LiveValidation('direccion', {validMessage: 'Ok', wait: 500});
	direccion.add(Validate.Presence, {failureMessage: "Escriba su Direccion."});
	//direccion.add(Validate.Format, {pattern: /^[A-Za-z0-9]+\s, failureMessage: "Direccion Invalida." });
}

function validarTelefono()
{
	var telefono = new LiveValidation('telefono', {validMessage: 'Ok', wait: 500});
	telefono.add(Validate.Presence, {failureMessage: "Escriba su Numero Telefonico"});
	telefono.add(Validate.Numericality, {onlyInteger: true, notANumberMessage: "Telefono solo debe contener numeros."});
	telefono.add(Validate.Length, {is: 11, wrongLengthMessage: "El numero telefonico debe contener 11 numeros."});
}

function CalcularResultado (formulario)
{
	var res = 0;
	for (i=0;i<formulario.elements.length;i++)
		if ((formulario.elements[i].type=="radio") &&
			 (formulario.elements[i].checked))
			  res = res + parseInt(formulario.elements[i].value);
		formulario.notatest.value = res;
}